#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define N 100100
#define int long long
#define M 400400
int n, q;
int op;
int l, r, k;
ll a[N], d[M], b[M];
using namespace std;

void build(int l, int r, int p)
{
    if (l == r)
    {
        d[p] = a[l];
        return;
    }
    int m = (l + r) >> 1;
    build(l, m, p * 2);
    build(m + 1, r, p * 2 + 1);
    d[p] = d[p * 2] + d[p * 2 + 1];
}

void update(int l, int r, int k, int s, int t, int p)
{
    if (l <= s && t <= r)
    {
        d[p] += (t - s + 1) * k;
        b[p] += k;
        return;
    }
    int m = s + ((t - s) >> 1);
    if (b[p])
    {
        d[p * 2] += b[p] * (m - s + 1);
        d[p * 2 + 1] += b[p] * (t - m);
        b[p * 2] += b[p];
        b[p * 2 + 1] += b[p];
        b[p] = 0;
    }
    if (l <= m)
    {
        update(l, r, k, s, m, p * 2);
    }
    if (r > m)  // 修正错误的条件
    {
        update(l, r, k, m + 1, t, p * 2 + 1);
    }
    d[p] = d[p * 2] + d[p * 2 + 1];
}

ll getSum(int l, int r, int s, int t, int p)
{
    if (l <= s && t <= r)
    {
        return d[p];
    }
    int m = (s + t) >> 1;
    if (b[p])
    {
        d[p * 2] += b[p] * (m - s + 1);
        d[p * 2 + 1] += b[p] * (t - m);
        b[p * 2] += b[p];
        b[p * 2 + 1] += b[p];
        b[p] = 0;
    }
    ll sum = 0;
    if (l <= m)
    {
        sum = getSum(l, r, s, m, p * 2);
    }
    if (r > m)  // 修正错误的条件
    {
        sum += getSum(l, r, m + 1, t, p * 2 + 1);
    }
    return sum;
}

void solve()
{
    cin >> n >> q;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
    }
    build(1, n, 1);
    while (q--)
    {
        cin >> op >> l >> r;
        if (op == 2)
        {
            ll res = getSum(l, r, 1, n, 1);
            cout << res << endl;
        }
        else
        {
            cin >> k;
            update(l, r, k, 1, n, 1);
        }
    }
}

signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    solve();
    return 0;
}
